<?php
/**
 * Created by PhpStorm.
 * User: root
 * Date: 6/19/17
 * Time: 11:35 AM
 */
class Catalog
{
    /**
     * 起始路径
     * @var
     */
    protected $startPath;

    protected $dirIndexes;

    public $indexData;

    public function __construct($path = '')
    {
        if ($path) {
            $this->startPath = $path;
        } else {
            $this->startPath = __DIR__;
        }
    }

    public function start()
    {
        $this->getIndex();
        $this->ansIndex();
    }

    public function getIndex()
    {
        if (is_dir($this->startPath)) {
            $this->dirIndexes = scandir($this->startPath);
        }
    }

    public function ansIndex()
    {
        foreach ($this->dirIndexes as $key => $index) {
            $this->indexData[$key]['name'] = $index;
            $this->indexData[$key]['path'] = str_replace('\\', '/', $this->startPath) .'/'. $index;
            if (is_dir($this->indexData[$key]['path'])) {
                $this->indexData[$key]['type'] = 1;
            } else {
                $this->indexData[$key]['type'] = 2;
            }

        }
    }
    

}